package oj;

import java.util.Scanner;

public class Day25S {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while (sc.hasNext()){
            String str=sc.nextLine();
            int sum=0;
            for (int i = 0; i < str.length(); i++) {
                sum+=str.charAt(str.length()-1-i)-'0';
            }
            while (sum>9){
                int num=0;
                while (sum>0){
                    int ret=sum%10;
                    num+=ret;
                    sum=sum/10;
                }
                sum=num;
            }
            System.out.println(sum);
        }
    }
}
